import { createStore } from "vuex"

import moduleA from "./modules/moduleA";
import moduleB from "./modules/moduleB";

export default createStore({
    modules: {
        a: moduleA,
        b: moduleB,
    },

    state: {
        count: 0,
        test: "hello world"
    },
    getters: {
        countAddFive: (state) => {
            return state.count + 5
        },
        countAddFiveAddTen: (state, getters) => {
            return getters.countAddFive + 10
        }
    },
    mutations: {
        add(state) {
            state.count++
        },
        addPlayload(state, Playload) {
            state.count += Playload.num
        }
    },
    actions: {
        // addAction(context){
        //     context.commit('add')
        // },
        addAction({ commit }) {
            commit('add')
        },
        asyncAddAction({commit}){
            setTimeout(() =>{
                commit('add')
            },1000)
        },

        asyncAddPlayloadAction({commit},Playload){
            setTimeout(()=>{
                commit('addPlayload',Playload)
            },1000)
        }
    }

})